data <- read.table("../data/mathanxiety.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "lowach", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# estimate means for centering
##################################################
# estimate sample statistics in lavaan
model <- "frlunch ~ 1; efficacy ~ 1; mathpost ~ 1; lowach ~ 1; stanread ~ 1; mathpre ~ 1;"
descriptives <- inspectSampleCov(model, data, meanstructure = TRUE, missing = "fiml")
descriptives
# center lower-order variable
data$mathpre.cgm <- data$mathpre - descriptives$mean[6]
summary(data[,c("frlunch","efficacy","mathpost","lowach","stanread")])
# set ranges (nodes) for pseudo-imputations
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = 1)
nodes.mathpost <- seq(25, 95, by = 1)
nodes.lowach <- c(0,1)
nodes.stanread <- c(20, 80, by = 1)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ condition + mathpre.cgm, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "linreg", "formula" = efficacy ~ frlunch + condition + mathpre.cgm, nodes = nodes.efficacy)
# model for mathpost outcome: f(mathpost|efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.mathpost)
# model for efficacy auxiliary variable: f(lowach|mathpost,efficacy,frlunch,condition,mathpre)
model.lowach <- list("model" = "logistic", "formula" = lowach ~ mathpost + condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.lowach)
# model for frlunch auxiliary variable: f(stanread|lowach,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "logistic", "formula" = stanread ~ lowach + mathpost + condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, mathpost = model.mathpost, lowach = model.lowach)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
# example x:linear regression with fiml estimation and categorical predictors
library(fdir)
library(mdmb)
library(lavaan)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("../data/mathanxiety.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "lowach", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# estimate means for centering
##################################################
# estimate sample statistics in lavaan
model <- "frlunch ~ 1; efficacy ~ 1; mathpost ~ 1; lowach ~ 1; stanread ~ 1; mathpre ~ 1;"
descriptives <- inspectSampleCov(model, data, meanstructure = TRUE, missing = "fiml")
descriptives
# center lower-order variable
data$mathpre.cgm <- data$mathpre - descriptives$mean[6]
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("frlunch","efficacy","mathpost","lowach","stanread")])
# set ranges (nodes) for pseudo-imputations
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = 1)
nodes.mathpost <- seq(25, 95, by = 1)
nodes.lowach <- c(0,1)
nodes.stanread <- c(20, 80, by = 1)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ condition + mathpre.cgm, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "linreg", "formula" = efficacy ~ frlunch + condition + mathpre.cgm, nodes = nodes.efficacy)
# model for mathpost outcome: f(mathpost|efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.mathpost)
# model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + I(frlunch-.411) + I(efficacy-3.355) + mathpre.cgm, nodes = nodes.mathpost)
# model for efficacy auxiliary variable: f(lowach|mathpost,efficacy,frlunch,condition,mathpre)
model.lowach <- list("model" = "logistic", "formula" = lowach ~ mathpost + condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.lowach)
# model for frlunch auxiliary variable: f(stanread|lowach,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ lowach + mathpost + condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, mathpost = model.mathpost, lowach = model.lowach)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
summary(fit)
# example x:linear regression with fiml estimation and categorical predictors
library(fdir)
library(mdmb)
library(lavaan)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("../data/mathanxiety.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "lowach", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# estimate means for centering
##################################################
# estimate sample statistics in lavaan
model <- "frlunch ~ 1; efficacy ~ 1; mathpost ~ 1; lowach ~ 1; stanread ~ 1; mathpre ~ 1;"
descriptives <- inspectSampleCov(model, data, meanstructure = TRUE, missing = "fiml")
descriptives
# center lower-order variable
data$mathpre.cgm <- data$mathpre - descriptives$mean[6]
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("frlunch","efficacy","mathpost","lowach","stanread")])
# set ranges (nodes) for pseudo-imputations
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = 1)
nodes.mathpost <- seq(25, 95, by = 1)
nodes.lowach <- c(0,1)
nodes.stanread <- c(20, 80, by = 1)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ condition + mathpre.cgm, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "oprobit", "formula" = efficacy ~ frlunch + condition + mathpre.cgm, nodes = nodes.efficacy)
# model for mathpost outcome: f(mathpost|efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.mathpost)
# model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + I(frlunch-.411) + I(efficacy-3.355) + mathpre.cgm, nodes = nodes.mathpost)
# model for efficacy auxiliary variable: f(lowach|mathpost,efficacy,frlunch,condition,mathpre)
model.lowach <- list("model" = "logistic", "formula" = lowach ~ mathpost + condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.lowach)
# model for frlunch auxiliary variable: f(stanread|lowach,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ lowach + mathpost + condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, mathpost = model.mathpost, lowach = model.lowach)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
# example x:linear regression with fiml estimation and categorical predictors
library(fdir)
library(mdmb)
library(lavaan)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("../data/mathanxiety.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "lowach", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# estimate means for centering
##################################################
# estimate sample statistics in lavaan
model <- "frlunch ~ 1; efficacy ~ 1; mathpost ~ 1; lowach ~ 1; stanread ~ 1; mathpre ~ 1;"
descriptives <- inspectSampleCov(model, data, meanstructure = TRUE, missing = "fiml")
descriptives
# center lower-order variable
data$mathpre.cgm <- data$mathpre - descriptives$mean[6]
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("frlunch","efficacy","mathpost","lowach","stanread")])
# set ranges (nodes) for pseudo-imputations
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = 1)
nodes.mathpost <- seq(25, 95, by = 1)
nodes.lowach <- c(0,1)
nodes.stanread <- c(20, 80, by = 1)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ condition + mathpre.cgm, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "linreg", "formula" = efficacy ~ frlunch + condition + mathpre.cgm, nodes = nodes.efficacy)
# model for mathpost outcome: f(mathpost|efficacy,frlunch,condition,mathpre)
# model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.mathpost)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + I(frlunch-.411) + I(efficacy-3.355) + mathpre.cgm, nodes = nodes.mathpost)
# model for efficacy auxiliary variable: f(lowach|mathpost,efficacy,frlunch,condition,mathpre)
model.lowach <- list("model" = "logistic", "formula" = lowach ~ mathpost + condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.lowach)
# model for frlunch auxiliary variable: f(stanread|lowach,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ lowach + mathpost + condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, mathpost = model.mathpost, lowach = model.lowach)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
summary(fit)
# example x:linear regression with fiml estimation and categorical predictors
library(fdir)
library(mdmb)
library(lavaan)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("../data/mathanxiety.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "lowach", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# estimate means for centering
##################################################
# estimate sample statistics in lavaan
model <- "frlunch ~ 1; efficacy ~ 1; mathpost ~ 1; lowach ~ 1; stanread ~ 1; mathpre ~ 1;"
descriptives <- inspectSampleCov(model, data, meanstructure = TRUE, missing = "fiml")
descriptives
# center lower-order variable
data$mathpre.cgm <- data$mathpre - descriptives$mean[6]
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("frlunch","efficacy","mathpost","lowach","stanread")])
# set ranges (nodes) for pseudo-imputations
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = 1)
nodes.mathpost <- seq(25, 95, by = 1)
nodes.lowach <- c(0,1)
nodes.stanread <- c(20, 80, by = 1)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ condition + mathpre.cgm, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "linreg", "formula" = efficacy ~ frlunch + condition + mathpre.cgm, nodes = nodes.efficacy)
# model for mathpost outcome: f(mathpost|efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + I(frlunch - .411) + I(efficacy - 3.355) + mathpre.cgm, nodes = nodes.mathpost)
# model for efficacy auxiliary variable: f(lowach|mathpost,efficacy,frlunch,condition,mathpre)
model.lowach <- list("model" = "logistic", "formula" = lowach ~ mathpost + condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.lowach)
# model for frlunch auxiliary variable: f(stanread|lowach,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ lowach + mathpost + condition + frlunch + efficacy + mathpre.cgm, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, mathpost = model.mathpost, lowach = model.lowach)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
summary(fit)
# example 3.1:linear regression with fiml estimation and categorical predictors
library(fdir)
library(mdmb)
library(lavaan)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("frlunch","efficacy","mathpost","atrisk","stanread")])
# example 3.1:linear regression with fiml estimation and categorical predictors
library(fdir)
library(mdmb)
library(lavaan)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("frlunch","efficacy","mathpost","atrisk","stanread")])
# set ranges (nodes) for pseudo-imputations
nodes.atrisk <- c(0,1)
nodes.stanread <- c(20, 80, by = 2)
nodes.mathpost <- seq(30, 90, by = 2)
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = 1)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ condition + mathpre, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "linreg", "formula" = efficacy ~ frlunch + condition + mathpre, nodes = nodes.efficacy)
# model for mathpost outcome: f(mathpost|efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + frlunch + efficacy + mathpre, nodes = nodes.mathpost)
# model for atrisk auxiliary variable: f(atrisk|mathpost,efficacy,frlunch,condition,mathpre)
model.atrisk <- list("model" = "logistic", "formula" = atrisk ~ mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.atrisk)
# model for stanread auxiliary variable: f(stanread|atrisk,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ atrisk + mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, mathpost = model.mathpost, atrisk = model.atrisk)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
summary(fit)
summary(data[,c("mathpost","stanread")])
# example 3.1:linear regression with fiml estimation and categorical predictors
library(fdir)
library(mdmb)
library(lavaan)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("mathpost","stanread")])
# example 3.1:linear regression with fiml estimation and categorical predictors
library(fdir)
library(mdmb)
library(lavaan)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("mathpost","stanread")])
# set ranges (nodes) for pseudo-imputations
nodes.atrisk <- c(0,1)
nodes.stanread <- c(20, 80, by = 2)
nodes.mathpost <- seq(30, 90, by = 2)
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = 1)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ condition + mathpre, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "oprobit", "formula" = efficacy ~ frlunch + condition + mathpre, nodes = nodes.efficacy)
# model for mathpost outcome: f(mathpost|efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + frlunch + efficacy + mathpre, nodes = nodes.mathpost)
# model for atrisk auxiliary variable: f(atrisk|mathpost,efficacy,frlunch,condition,mathpre)
model.atrisk <- list("model" = "logistic", "formula" = atrisk ~ mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.atrisk)
# model for stanread auxiliary variable: f(stanread|atrisk,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ atrisk + mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, mathpost = model.mathpost, atrisk = model.atrisk)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
# example 3.1:linear regression with fiml estimation and categorical predictors
library(fdir)
library(mdmb)
library(lavaan)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("mathpost","stanread")])
# set ranges (nodes) for pseudo-imputations
nodes.atrisk <- c(0,1)
nodes.stanread <- c(20, 80, by = 2)
nodes.mathpost <- seq(30, 90, by = 2)
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = 1)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ condition + mathpre, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "linreg", "formula" = efficacy ~ frlunch + condition + mathpre, nodes = nodes.efficacy)
# model for mathpost outcome: f(mathpost|efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + frlunch + efficacy + mathpre, nodes = nodes.mathpost)
# model for atrisk auxiliary variable: f(atrisk|mathpost,efficacy,frlunch,condition,mathpre)
model.atrisk <- list("model" = "logistic", "formula" = atrisk ~ mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.atrisk)
# model for stanread auxiliary variable: f(stanread|atrisk,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ atrisk + mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, mathpost = model.mathpost, atrisk = model.atrisk)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
# example 3.1:linear regression with fiml estimation and categorical predictors
library(fdir)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("mathpost","stanread")])
# set ranges (nodes) for pseudo-imputations
nodes.atrisk <- c(0,1)
nodes.stanread <- c(20, 80, by = 2)
nodes.mathpost <- seq(30, 90, by = 2)
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = 1)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ condition + mathpre, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "linreg", "formula" = efficacy ~ frlunch + condition + mathpre, nodes = nodes.efficacy)
# model for mathpost outcome: f(mathpost|efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + frlunch + efficacy + mathpre, nodes = nodes.mathpost)
# model for atrisk auxiliary variable: f(atrisk|mathpost,efficacy,frlunch,condition,mathpre)
model.atrisk <- list("model" = "logistic", "formula" = atrisk ~ mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.atrisk)
# model for stanread auxiliary variable: f(stanread|atrisk,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ atrisk + mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, mathpost = model.mathpost, atrisk = model.atrisk)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
# example 3.1:linear regression with fiml estimation and categorical predictors
library(fdir)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("mathpost","stanread")])
# set ranges (nodes) for pseudo-imputations
nodes.atrisk <- c(0,1)
nodes.stanread <- c(20, 80, by = 2)
nodes.mathpost <- seq(30, 90, by = 2)
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = 1)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "linreg", "formula" = frlunch ~ condition + mathpre, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "linreg", "formula" = efficacy ~ frlunch + condition + mathpre, nodes = nodes.efficacy)
# model for mathpost outcome: f(mathpost|efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + frlunch + efficacy + mathpre, nodes = nodes.mathpost)
# model for atrisk auxiliary variable: f(atrisk|mathpost,efficacy,frlunch,condition,mathpre)
model.atrisk <- list("model" = "linreg", "formula" = atrisk ~ mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.atrisk)
# model for stanread auxiliary variable: f(stanread|atrisk,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ atrisk + mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, mathpost = model.mathpost, atrisk = model.atrisk)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
# example 3.1:linear regression with fiml estimation and categorical predictors
library(fdir)
library(mdmb)
library(lavaan)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("frlunch","efficacy","mathpost","atrisk","stanread")])
# set ranges (nodes) for pseudo-imputations
nodes.atrisk <- c(0,1)
nodes.stanread <- c(20, 80, by = 2)
nodes.mathpost <- seq(30, 90, by = 2)
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = 1)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ condition + mathpre, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "linreg", "formula" = efficacy ~ frlunch + condition + mathpre, nodes = nodes.efficacy)
# model for mathpost outcome: f(mathpost|efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + frlunch + efficacy + mathpre, nodes = nodes.mathpost)
# model for atrisk auxiliary variable: f(atrisk|mathpost,efficacy,frlunch,condition,mathpre)
model.atrisk <- list("model" = "logistic", "formula" = atrisk ~ mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.atrisk)
# model for stanread auxiliary variable: f(stanread|atrisk,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ atrisk + mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, mathpost = model.mathpost, atrisk = model.atrisk)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
##################################################
# fiml regression w binary and ordinal predictors
##################################################
library(fdir)
library(mdmb)
##################################################
# set working directory and load data
##################################################
set()
load('mathachievement.rda')
##################################################
# analysis
##################################################
# summaries to determine ranges for pseudo-imputations
summary(mathachievement)
# set ranges (nodes) for pseudo-imputations
nodes.atrisk <- c(0,1)
nodes.stanread <- c(20, 80, by = 2)
nodes.mathpost <- seq(30, 90, by = 2)
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = 1)
# model for frlunch predictor
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ condition + mathpre, nodes = nodes.frlunch)
# model for efficacy predictor
model.efficacy <- list("model" = "linreg", "formula" = efficacy ~ frlunch + condition + mathpre, nodes = nodes.efficacy)
# model for mathpost outcome
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ condition + frlunch + efficacy + mathpre, nodes = nodes.mathpost)
# model for atrisk auxiliary variable
model.atrisk <- list("model" = "logistic", "formula" = atrisk ~ mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.atrisk)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ atrisk + mathpost + condition + frlunch + efficacy + mathpre, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, mathpost = model.mathpost, atrisk = model.atrisk)
# estimate factored regression model w mdmb
fit <- frm_em(dat = mathachievement, dep = model.stanread, ind = predictor.models)
